import request from '@/utils/request'

export default {
    getAllBookCounts(){
        const req = request({
            method: 'get',
            url: '/dgut/getAllBookMessage'
        })
        return req;
    },
    getAllBookClassify(){
        const req = request({
            method: 'get',
            url: '/dgut/getAllBookClassify'
        })
        return req;
    },
    editOneBook(bookMessage){
        const req = request({
            method: 'put',
            url: '/dgut/updateOneBookMessage',
            params: {
                codes:sessionStorage.getItem("codes"),
                bookId:bookMessage.bookId,
                bookName: bookMessage.bookName,
                bookSynopsis: bookMessage.bookSynopsis,
                bookOprice: bookMessage.bookOprice,
                bookPprice: bookMessage.bookPprice,
                bookCounts: bookMessage.bookCounts,
                bookUrl: bookMessage.bookUrl,
                bookISBN: bookMessage.bookISBN,
                bookCategoryId: bookMessage.bookCategoryId,
                bookTag: bookMessage.bookTag

            }
        })
        return req;
    },
    getOneBook(bookId){
        const req = request({
            method: 'get',
            url: '/dgut/getOneBookMessageById',
            params: {
                bookId
            }
        })
        return req;
    },
    deleteOneBook(bookId){
        const req = request({
            method: 'delete',
            url: '/dgut/deleteOneBookMessage',
            params:{
                codes:sessionStorage.getItem("codes"),
                bookId
            }
        })
        return req;
    },
    addOneBook(bookMessage) {
        const req = request({
            method: 'post',
            url: '/dgut/addOneBookMessage',
            params: {
                codes:sessionStorage.getItem("codes"),
                bookName: bookMessage.bookName,
                bookSynopsis: bookMessage.bookSynopsis,
                bookOprice: bookMessage.bookOprice,
                bookPprice: bookMessage.bookPprice,
                bookCounts: bookMessage.bookCounts,
                bookUrl: bookMessage.bookUrl,
                bookISBN: bookMessage.bookISBN,
                bookCategoryId: bookMessage.bookCategoryId,
                bookTag: bookMessage.bookTag
            }
        })
        return req;
    },
    search(searchMap) {
        if (searchMap.bookId != "") {
            console.log("hhhhhhhhhhh")
            const req = request({
                method: 'get',
                url: '/dgut/getOneBookMessageById',
                params: {
                    bookId:searchMap.bookId
                }
            })
            return req;
        } else if (searchMap.bookName != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getAllBookMessageByName',
                params: {
                    bookName:searchMap.bookName
                }
            })
            return req;
        } else if (searchMap.bookISBN != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getAllBookMessageByISBN',
                params: {
                    bookISBN:searchMap.bookISBN
                }
            })
            return req;
        } else if (searchMap.bookCategory != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getAllBookMessageByCategory',
                params: {
                    bookCategory:searchMap.bookCategory
                }
            })
            return req;
        } else if(searchMap.bookTag != ""){
            const req = request({
                method: 'get',
                url: '/dgut/getAllBookMessageByTag',
                params: {
                    bookTag:searchMap.bookTag
                }
            })
            return req;
        }else{
            const req = request({
                method: 'get',
                url: '/dgut/getAllBookMessage'
            })
            return req;
        }
    }
}